export const addDicName = (list) => {
  list.forEach(i => {
    if (i.dicName) {
      i.type = "select";
      i.dicUrl = "/system/dict/dictionary?code=" + i.dicName;
      i.props = {
        label: "dictValue",
        value: "dictKey"
      }
      delete i.dicName
    }
  })
}

export const clone = (obj) => {
  return JSON.parse(JSON.stringify(obj));
}

export const cleanWord = (word, replacements) => {
  let cleaned = word;
  replacements.forEach(replacement => {
    cleaned = cleaned.replace(replacement, '');
  });
  return cleaned.trim(); // 去除前后空格
};

export const areSimilar = (label1, label2, specialReplacements) => {
  // 定义需要替换的词语
  const replacements = specialReplacements.concat(["编码", "编号", "代码"]);

  const t1 = cleanWord(label1, replacements)
  const t2 = cleanWord(label2, replacements)

  // 比较处理后的词语
  return t1 === t2;
}

export const getColumnRefs = (json) => {
  const columnRefs = [];

  function traverseObject(obj) {
    if (Array.isArray(obj)) {
      obj.forEach(item => traverseObject(item));
    } else if (typeof obj === 'object' && obj !== null) {
      if (obj.hasOwnProperty('column')) {
        columnRefs.push(obj);
      }
      Object.values(obj).forEach(value => traverseObject(value));
    }
  }

  traverseObject(json);
  return columnRefs;
}